package spring.yongongsystem.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import spring.yongongsystem.POJO.dto.GroupPageQueryDTO;
import spring.yongongsystem.POJO.entity.Category;
import spring.yongongsystem.POJO.entity.Group;
import spring.yongongsystem.mapper.GroupMapper;
import spring.yongongsystem.result.PageResult;
import spring.yongongsystem.service.GroupService;

@Service
public class GroupServiceImpl implements GroupService {
    @Autowired
    private GroupMapper groupMapper;

    @Override
    public void save(Group group) {
        groupMapper.insert(group);
    }

    @Override
    public PageResult pageQuery(GroupPageQueryDTO groupPageQueryDTO) {
        PageHelper.startPage(groupPageQueryDTO.getPage(),groupPageQueryDTO.getPageSize());
        //下一条sql进行分页，自动加入limit关键字分页
        Page<Group> page = groupMapper.pageQuery(groupPageQueryDTO);
        return new PageResult(groupMapper.count(), page.getResult());
    }

    @Override
    public void deleteById(Long id) {
        groupMapper.deleteById(id);
    }

    @Override
    public void update(Group group) {
        groupMapper.update(group);
    }
}
